package org.lzuploader.model.result;

import java.util.Set;
import java.util.TreeSet;

/** This class contains the results of a {@link org.lzuploader.controller.NetUploader} when the upload is successfull.
 * 
 * @author Emmanuel Cron
 *
 */
public class Result
{
    /** Number of items that have been deleted for an update. */
    private int itemsDeleted = -1;
    
    /** Number of items that have been updated. */
    private int itemsUpdated = -1;
    
    /** Number of spells that have been deleted for an updated. */
    private int spellsDeleted = -1;
    
    /** Number of spells that have been updated. */
    private int spellsUpdated = -1;
    
    /** Wether the account's status has been updated or not. */
    private boolean statusUpdated;
    
    /** A list of {@link ResultCharacter}, each representing a character's upload result. */
    private Set<ResultCharacter> importedCharacters = new TreeSet<ResultCharacter>();
    
    /** Returns the number of items deleted.
     * 
     * @return Number of items deleted, or <code>-1</code> if an error occured.
     */
    public int getItemsDeleted()
    {
        return itemsDeleted;
    }
    
    /**
     * Sets the number of items deleted.
     * @param newItemsDeleted Number of items
     */
    public void setItemsDeleted(final int newItemsDeleted)
    {
        itemsDeleted = newItemsDeleted;
    }
    
    /** Returns the number of items updated.
     * 
     * @return Number of items updated, or <code>-1</code> if an error occured.
     */
    public int getItemsUpdated()
    {
        return itemsUpdated;
    }
    
    /**
     * Sets the number of items udpated.
     * @param newItemsUpdated Number of items
     */
    public void setItemsUpdated(final int newItemsUpdated)
    {
        itemsUpdated = newItemsUpdated;
    }
    
    /** Returns the number of spells deleted.
     * 
     * @return Number of spells deleted, or <code>-1</code> if an error occured.
     */
    public int getSpellsDeleted()
    {
        return spellsDeleted;
    }
    
    /**
     * Sets the number of spells deleted.
     * @param newSpellsDeleted Number of spells.
     */
    public void setSpellsDeleted(final int newSpellsDeleted)
    {
        spellsDeleted = newSpellsDeleted;
    }
    
    /** Returns the number of spells updated.
     * 
     * @return Number of spells updated, or <code>-1</code> if an error occured.
     */
    public int getSpellsUpdated()
    {
        return spellsUpdated;
    }
    
    /**
     * Sets the number of spells updated.
     * @param newSpellsUpdated Number of spells.
     */
    public void setSpellsUpdated(final int newSpellsUpdated)
    {
        spellsUpdated = newSpellsUpdated;
    }
    
    /** Returns wether the account's status has been updated.
     * 
     * @return <code>true</code> if the account's status has been updated, <code>false</code> otherwise.
     */
    public boolean isStatusUpdated()
    {
        return statusUpdated;
    }
    
    /**
     * Sets wether the status has been updated or not.
     * @param newStatusUpdated <code>true</code> if the status has been updated, <code>false</code> otherwise.
     */
    public void setStatusUpdated(final boolean newStatusUpdated)
    {
        statusUpdated = newStatusUpdated;
    }
    
    /** Returns the list of imported characters.
     * The list can be empty if no character has been updated.
     * @return List of results for imported characters.
     */
    public Set<ResultCharacter> getImportedCharacters()
    {
        return importedCharacters;
    }
    
    /**
     * Returns a string representing this class in a human readable way.
     * @return A string representing this class.
     */
    @Override
    public String toString()
    {
        final StringBuffer sb = new StringBuffer();
        
        sb.append("[ ");
        sb.append("Items deleted: " + itemsDeleted + ", ");
        sb.append("Items updated: " + itemsUpdated + ", ");
        sb.append("Spells deleted: " + spellsDeleted + ", ");
        sb.append("Spells updated: " + spellsUpdated + ", ");
        sb.append("Imported characters: " + importedCharacters.size());
        sb.append(" ]\n");
        
        sb.append("{\n");
        for (ResultCharacter rc : importedCharacters)
        {
            sb.append(rc.toString() + "\n");
        }
        sb.append("}");
        
        return sb.toString();
    }
}
